package cn.zqh.brand.rabbitmq;

import cn.hutool.json.JSONObject;
import cn.zqh.bean.api.CommonResult;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: zqh
 * @Date: 2023-03-15-13:47
 * @Description: rabbitmq服务$
 */
@Component
public class MyConsumer2 {

    @Autowired
    private RestTemplate restTemplate;

    @RabbitListener(queues = "ms_queue8")
    public void process(Message message){
        byte[] body = message.getBody();
        JSONObject entries = new JSONObject(body);
        Double money = entries.getDouble("money");
        CommonResult commonResult2 = restTemplate.postForObject("http://127.0.0.1:9501/user/addMoney?money=" + money, "", CommonResult.class);
        System.out.println("店主钱增加");
    }

}
